<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="midHostname" value='<%=ServerValue.getMidHostname()%>'/>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<script language="javascript">
	$().ready( function() {
		$('#startDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDate').datepick({minDate: new Date(),showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		$("#subBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("10");
				$("#cateBannerAdvForm").submit();
			}
		});


		$("#draftBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("00");
				$("#cateBannerAdvForm").submit();
			}
		});
		
		$("#canBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("90");
				$("#cateBannerAdvForm").submit();
			}
		});
	});
	
	function validate_data(){
		if ( $("#advName").val() == "" ){
			alert("请输入广告名称");
			$("#advName").focus();
			return false;
		}
		if ( $("#advType").val() == "" ){
			alert("请选择广告类型");
			$("#advType").focus();
			return false;
		}
		if ( $("#startDate").val() == ""){
			alert("请输入起始时间");
			$("#startDate").focus();
			return false;
		}
		if( $("#endDate").val() == "" ){
			alert("请输入结束时间");
			$("#endDate").focus();
			return false;
		}
		
		if ( $("#advId").val() == "" ){
			if ( $("#bannerImg").val() == "" ){
				alert("请选择广告图片");
				$("#bannerImg").focus();
				return false;
			}
		}

		if ( $("#bannerImgLink").val() == ""){
				alert("请输入图片点击连结");
				$("#bannerImgLink").focus();
				return false;
		}
		if ( !isURL($("#bannerImgLink").val())){
			alert("图片点击连结格式错误");
			$("#bannerImgLink").focus();
			return false;
		}
		
		for( var i = 1; i <= 3; i++ ){
			if ( $("#bannerTag" + i ).val() == "" ){
				alert("请输入Tab标题文字 " + i);
				$("#bannerTag" + i ).focus();
				return false;
			}
			if ( $("#bannerContent" + i ).val() == ""){
				alert("请输入文字内容 " + i );
				$("#bannerContent" + i ).focus();
				return false;
			}
			if ( $("#bannerLink" + i ).val() == ""){
				alert("请输入文字连结 " + i );
				$("#bannerLink" + i ).focus();
				return false;
			}
			if ( !isURL($("#bannerLink" + i ).val())){
				alert("文字连结 " + i +"格式错误");
				$("#bannerLink" + i ).focus();
				return false;
			}			
		}
		if ( $("#bannerImg").val() != "" )
			$("#bannerImgName").val($("#bannerImg").val());
		return true;
	}
	
</script>
<s:actionerror />
<s:actionmessage />
<s:fielderror />
<h1>馆首页主打商品banner</h1>
<s:form action="cateMainProd/saveCateBannerAdv.do" method="post" name="cateBannerAdvForm" id="cateBannerAdvForm" enctype="multipart/form-data">
	<table class="tb-data" width="100%">
		<tbody>
			<tr style="display:none;">
				<th>类型</th>
				<td>
					<c-rt:if test="${advType eq '000_BANNER'}">馆首页主打商品Banner</c-rt:if>
					<c-rt:if test="${advType eq '100_BANNER'}">分类页主打商品Banner</c-rt:if>
					<input type="hidden" id="advType" name="advType" value="${advType}"/>
				</td>
			</tr>
			<tr>
				<th>广告名称</th>
				<td><input type="text" id="advName" name="advName" value="${advName}" size="30" maxlength="30"/></td>
			</tr>
			<tr>
				<th>起迄时间</th>
				<td>
				<!--
				<c-rt:choose>
				
					<c-rt:when test="${not empty advId}">
						${startDate} ~ 
						<input type="hidden" id="startDate" name="startDate" value="${startDate}"/>
					</c-rt:when>
					<c-rt:otherwise>
						<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/> ~ 
					</c-rt:otherwise>
				</c-rt:choose>
				  -->
				<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/> ~ 
				<input type="text" id="endDate" name="endDate" value="${endDate}" maxlength="10"/>
				</td>
			</tr>
			<tr>
				<th>馆别</th>
				<td>
					<select id="mainCateId" name="mainCateId">
						<c-rt:forEach items="${categoryRoot}" var="category">
							<option value="${category.id}" ${mainCateId eq category.id ? "selected" : ""}>${category.name}</option>
						</c-rt:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<th>位置</th>
				<td>
					<select id="advTarget" name="advTarget">
						<option value="TOP"  ${advTarget eq "TOP" ? "selected" : ""}>上</option>
						<option value="MID" ${advTarget eq "MID" ? "selected" : ""}>中</option>
						<option value="BTM" ${advTarget eq "BTM" ? "selected" : ""}>下</option>
					</select>
				</td>
			</tr>
			<tr>
				<th>Banner</th>
				<td>
					<c-rt:if test="${not empty advId}">
						<img src="${midHostname}/eventImg/${bannerImgFolder}/${advType}/${bannerImgName}" width="280" height="70"/><br/>
					</c-rt:if>
					<b>广告图片:</b><s:file id="bannerImg" name="bannerImg" value="" size="60" ></s:file><br/>
					<span class="txt-rd">图片尺寸:280X70</span><BR/>
					<b>图片点击连结:</b><input type="text" name="bannerImgLink" id="bannerImgLink" value="${bannerImgLink}" size="100"/><br/>
					<span class="txt-rd">ex:http://www.yaodian100.com</span>
					<input type="hidden" id="bannerImgName" name="bannerImgName" value="${bannerImgName}"/>
					<input type="hidden" name="bannerImgFolder" value="${bannerImgFolder}"/>
				</td>
			</tr>
			<tr>
				<th>文字1</th>
				<td>
					<b>Tab 标题文字:</b>
						<s:select name="bannerTag1" list="advBannerTagMenu.options" id="bannerTag1" value="bannerTag1" listKey="key" listValue="value.name"></s:select><br/>
					<b>文字内容:</b><input type="text" name="bannerContent1" id="bannerContent1" maxlength="10" size="25" value="${bannerContent1}"/> <span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>文字连结:</b><input type="text" name="bannerLink1" id="bannerLink1"  size="100" value="${bannerLink1}"/><br/>
					<span class="txt-rd">ex:http://www.yaodian100.com</span>
				</td>
			</tr>
			<tr>
				<th>文字2</th>
				<td>
					<b>Tab 标题文字:</b>
						<s:select name="bannerTag2" list="advBannerTagMenu.options" id="bannerTag2" value="bannerTag2" listKey="key" listValue="value.name"></s:select><br/>
					<b>文字内容:</b><input type="text" name="bannerContent2" id="bannerContent2" maxlength="10" size="25" value="${bannerContent2}"/> <span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>文字连结:</b><input type="text" name="bannerLink2" id="bannerLink2"  size="100" value="${bannerLink2}"/><br/>
					<span class="txt-rd">ex:http://www.yaodian100.com</span>
				</td>
			</tr>
			<tr>
				<th>文字3</th>
				<td>
					<b>Tab 标题文字:</b>
						<s:select name="bannerTag3" list="advBannerTagMenu.options" id="bannerTag3" value="bannerTag3" listKey="key" listValue="value.name"></s:select><br/>
					<b>文字内容:</b><input type="text" name="bannerContent3" id="bannerContent3" maxlength="10" size="25" value="${bannerContent3}"/> <span class="txt-rd">字数限制:10个中文字</span><br/>
					<b>文字连结:</b><input type="text" name="bannerLink3" id="bannerLink3"  size="100" value="${bannerLink3}"/><br/>
					<span class="txt-rd">ex:http://www.yaodian100.com</span>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<input type="hidden" id="advId" name="advId" value="${advId}"/>
					<input type="hidden" id="advStatus" name="advStatus" value="${advStatus}"/>
					<input type="button" id="subBtn" name="subBtn" value="发送"/>
					<input type="button" id="draftBtn" name="draftBtn" value="草稿"/>
					<input type="button" id="canBtn" name="canBtn" value="暂停"/>
				</td>
			</tr>												
		</tbody>
	</table>
</s:form>
<div class="f-link">
	<a href="${midContextPath}/generate/cateMainProd/search.do">回广告查询页</a>
</div>